#include <stdlib.h>
#include <sstream>
#include "Matrix.h"
using namespace std;
int Matrix :: MatrixMultiplication(int a, int b, int c, int d, int e, int f, int g, int h)
{
int sum=0;
int i;
int j;
int k;
int A[2][2], B[2][2], Result[2][2];
  
  
cout << "The elements of first matrix"<<endl;
A[0][0]=a;
A[0][1]=b;
A[1][0]=c;
A[1][1]=d;
for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
      {
        cout << A[i][j];
	cout << "\t";
      }
 	
      cout << endl;
    }
cout << "The elements of second matrix"<<endl;

B[0][0]=e;
B[0][1]=f;
B[1][0]=g;
B[1][1]=h;
for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
      {
        cout << B[i][j];
	cout << "\t";
      }
 	
      cout << endl;
    }
for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
      {
        for ( k = 0 ; k < 2 ; k++ )
        {
          sum = sum + A[i][k]*B[k][j];
        }
 
        Result[i][j] = sum;
        sum = 0;
      }
    }
 
    cout << "Product of entered matrices:-" << endl;
 
    for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
      {
        cout << Result[i][j];
	cout << "\t";
      }
 	
      cout << endl;
    }
ostringstream s;
s << Result[0][0] << Result[0][1] << Result[1][0] << Result[1][1];
istringstream in(s.str());
int ic;
in >> ic;
cout << "Product Array: " << ic << endl;
 
  return ic;
}

int Matrix :: MatrixAddition(int a, int b, int c, int d, int e, int f, int g, int h)
{
int sum=0;
int i;
int j;
int k;
int A[2][2], B[2][2], Result[2][2], tobereturn=0;
A[0][0]=a;
A[0][1]=b;
A[1][0]=c;
A[1][1]=d;
cout << "The elements of first matrix"<<endl;
for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
      {
        cout << A[i][j];
	cout << "\t";
      }
 	
      cout << endl;
    }
B[0][0]=e;
B[0][1]=f;
B[1][0]=g;
B[1][1]=h;
cout << "The elements of second matrix"<<endl;
for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
      {
        cout << B[i][j];
	cout << "\t";
      }
 	
      cout << endl;
    }
Result[0][0]=A[0][0]+B[0][0];
Result[0][1]=A[0][1]+B[0][1];
Result[1][0]=A[1][0]+B[1][0];
Result[1][1]=A[1][1]+B[1][1];


ostringstream s;
s << Result[0][0] << Result[0][1] << Result[1][0] << Result[1][1];
istringstream in(s.str());
int ic;
in >> ic;
cout << "Sum array: " << ic << endl;
cout << "Sum of entered matrices:-" << endl;
for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
        cout << Result[i][j] << "\t";
 
      cout << endl;
    }

  return ic;
}

int Matrix :: MatrixSubtraction(int a, int b, int c, int d, int e, int f, int g, int h)
{
int sum=0;
int i;
int j;
int k;
int A[2][2], B[2][2], Result[2][2];
A[0][0]=a;
A[0][1]=b;
A[1][0]=c;
A[1][1]=d;
cout << "The elements of first matrix"<<endl;
for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
      {
        cout << A[i][j];
	cout << "\t";
      }
 	
      cout << endl;
    }
B[0][0]=e;
B[0][1]=f;
B[1][0]=g;
B[1][1]=h;
cout << "The elements of second matrix"<<endl;
for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
      {
        cout << B[i][j];
	cout << "\t";
      }
 	
      cout << endl;
    }
Result[0][0]=A[0][0]-B[0][0];
Result[0][1]=A[0][1]-B[0][1];
Result[1][0]=A[1][0]-B[1][0];
Result[1][1]=A[1][1]-B[1][1];

ostringstream s;
s << Result[0][0] << Result[0][1] << Result[1][0] << Result[1][1];
istringstream in(s.str());
int ic;
in >> ic;
cout << "Difference Array: " << ic << endl;
cout << "Difference of entered matrices:-" << endl;
for ( i = 0 ; i < 2 ; i++ )
    {
      for ( j = 0 ; j < 2 ; j++ )
        cout << Result[i][j] << "\t";
 
      cout << endl;
    }
  return ic;
}

int main()
{
Matrix obj;
obj.MatrixMultiplication(2,2,2,2,2,2,2,2);
obj.MatrixAddition(2,2,2,2,2,2,2,2);
obj.MatrixSubtraction(4,2,2,2,2,2,2,2);
return 0;
}
